package com.trkj.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.dao.jpa.CcDoctorAdviceDAO;
import com.trkj.pojos.CcDoctorAdvice;
import com.trkj.service.CcDoctorAdviceService;
import com.trkj.vo.CcDoctorAdviceVo;
import com.trkj.vo.Result;

@Controller
public class CcDoctorAdviceController {

	//private static final String carraService = null;
	@Autowired
	private CcDoctorAdviceService cdaService;
	
	@RequestMapping("/cc_toqueryBydoctorid")
	public @ResponseBody Map<String, Object> queryBydoctorid(int page,int rows,String doctorid){
		return cdaService.queryBydoctorid(page, rows, doctorid);
	}
	@RequestMapping("/tocc_addCcDoctorAdvice")
	public @ResponseBody Result addCcDoctorAdvice(String printstaff,String elePerid,String adName){
		if(printstaff!=null&&elePerid!=null&&adName!=null){
			CcDoctorAdvice c=new CcDoctorAdvice();
			c.setAdName(adName);
			c.setElePerid(new BigDecimal(elePerid));
			c.setPrintstaff(new BigDecimal(printstaff));
			cdaService.addCcDoctorAdvice(c);
		}
		
		return  new Result(true,"操作成功！");
		
	}
	@RequestMapping("/tocc_deleteCcDoctorAdvice")
	public @ResponseBody Result deleteCcDoctorAdvice(long[] list){
			System.err.println(list.length);
			if(list.length>0){
				cdaService.deleteCDA(list);
				return  new Result(true,"删除成功！");
			}else{
				return  new Result(false,"删除失败！");
			}
			
	}
	@RequestMapping("/tocc_updateCcDoctorAdvice")
	public @ResponseBody Result updateCcDoctorAdvice(CcDoctorAdvice cda){

			boolean jg=cdaService.updateCcDoctorAdvice(cda);
			if(jg){
				return  new Result(true,"修改成功！");
			}else{
				return  new Result(false,"修改失败！");
			}
			
	}
	@RequestMapping("/tocc_queryByOne")
	public @ResponseBody CcDoctorAdvice queryByOne(String adid){
		if(adid!=null){
			return cdaService.queryOne(Long.parseLong(adid));
		}else{
			return null;
		}
	}
	@RequestMapping("/tocc_queryByPname")
	public @ResponseBody List<CcDoctorAdviceVo> queryByPname(String pname){
			return cdaService.queryByPname(pname);
	}
}
